package shapewar.engine.model.abst;

import shapewar.engine.intefac.IView;
import shapewar.view.myview.MyView;

public abstract class Model extends Obj implements IView{
	public static final int Circle = 0;
	public static final int Polygon = 1;
	
	public int shape;
	public float v[][];
	public float r;
	
	public MyView view;
	public Model(int id,float x,float y,float r,int depth){
		super(id, x, y, depth);
		this.r = r;
		this.shape = Model.Circle;
	}
	
	public Model(int id,float x,float y,float v[][],int depth){
		super(id, x, y, depth);
		this.v = v;
		this.shape = Model.Polygon;
		if(v!=null)
			updateRadium();
	}
	
	public abstract void init();
	public abstract void destory();

	@Override
	public void setView(MyView view){
		this.view = view;
	}
	@Override
	public MyView getView(){
		return view;
	}
	@Override
	public Model getModel() {
		return this;
	}
	
	public float[][] getV(){
		return v;
	}
	
	protected void updateRadium(){
		float max = Float.MIN_VALUE;
		for(int i=0;i<v.length;i++){
			float dis = (float)Math.sqrt((v[i][0]-_x)*(v[i][0]-_x)+(v[i][1]-_y)*(v[i][1]-_y));
			max = dis>max?dis:max;
		}
		r = max;
	}
	
}
